﻿app.controller('NewMessageController', function ($scope, $rootScope, notificationFactory) {
    init();

    function init() {
        $scope.severName = mainFileAddress;
        $scope.roleByGroup = JSON.parse(localStorage.getItem("menu"));
        $scope.userName = $rootScope.userName;
        //count--------------
        notificationFactory.countAddFriend(localStorage.getItem("idkey")).success(function (data) {
            $scope.countAddFriend = data;
        });
        notificationFactory.countFromRoom(localStorage.getItem("idkey")).success(function (data) {
            $scope.countFromRoom = data;
        });
        notificationFactory.countNewMessage(localStorage.getItem("idkey")).success(function (data) {
            $scope.countNewMessage = data;
        });
        
        //load item----------
        notificationFactory.getNewComment(localStorage.getItem("idkey")).success(function (data) {
            $scope.getNewComment = data;
        });

        //thao tác với danh sách notificaton----------------------------------------------------------
        $scope.deleteNotification = function (id) {
            $('#newComment_' + id).fadeOut();
            notificationFactory.deleteNotification(id);
        };


        createMenu();
        $scope.status = false;
        disableLoadding();
        $scope.loadding = false;
        $scope.out = function () {
            logout();
        };
    }

});














function disableLoadding() {
    $("#preloader").fadeOut(1000);
}
function logout() {
    localStorage.removeItem("idkey");
    localStorage.removeItem("authen");
    localStorage.removeItem("menu");
    window.location.href = '#/login';
}
function createMenu() {
    //$('#scrollbar1').tinyscrollbar();

    var snapper = new Snap({
        element: document.getElementById('content')
    });
    $('.deploy-sidebar, .close-icon').click(function () {
        if (snapper.state().state == "left") {
            snapper.close();
        } else {
            snapper.open('left');
        }
        return false;
    });
    $('.page-content').click(function () {
        snapper.close();
    });
}
function toggle() {
    $('.show-toggle-v4').hide();
    $('.toggle-content-v4').hide();
    $('.show-toggle-v4').click(function () {
        $(this).hide();
        $(this).parent().find('.hide-toggle-v4').show();
        $(this).parent().find('.toggle-content-v4').fadeOut(100);
        return false;
    });
    $('.hide-toggle-v4').click(function () {
        $(this).parent().find('.show-toggle-v4').show();
        $(this).hide(); $(this).parent().find('.toggle-content-v4').fadeIn(200);
        return false;
    });

}